#!/bin/bash

set -e

r=$1

if [ -z "$r" ]; then
   echo "must provide repo url"
   exit 1
fi

repo=$(basename $r)

pushd /mnt/NAS/git-repos &>/dev/null
if [ -d "$repo" ]; then
   echo "Repo $repo alread exists, abort"
   exit 0
fi

echo "creating repo: $repo ..."
mkdir $repo
pushd $repo &>/dev/null
git init --bare
popd &>/dev/null
chown -R git:git $repo
popd &>/dev/null
echo "new repo: ssh://git@192.168.0.11:/mnt/NAS/git-repos/$repo"
echo " done"

